layui.use(['layer', 'form','jquery'], function(){

	var form= layui.form,
		layer=layui.layer,
		$=layui.jquery;

    /**
	 * 监听表单的提交事件
     */
    form.on('submit(login)', function(data){

        //当前容器的全部表单字段，名值对形式：{name: value}
        // console.log(data.field);

		if (isEmpty(data.field.username)){
			layer.msg("用户名称不能为空!",{icon:5});
			return false;
		}
		if (isEmpty(data.field.password)){
            layer.msg("用户密码不能为空!",{icon:5});
            return false;
		}

		var username=data.field.username;
		$.ajax({

			type:"post",
			url:"../login/loginVerification",
			data:{
				username:data.field.username,
				password:data.field.password
			},
			success:function (data) {
				if (data.msg=="登录成功"){

					window.location.href="home.html?"+username+"";
				}else {
					layer.msg(data.msg,{icon:5});

				}
            }

		})

		//点击按钮表单默认会提交,设置为return false,可以阻止表单提交
        return false;

    });

});


function isEmpty(str) {
	if (str == null || str.trim()==""){
		return true;
	} else {
		return false;
	}
}